#设置最小CMAKE版本
cmake_minimum_required(VERSION 3.13)
#设置工程名称及编译器
project(VideoSubFinder LANGUAGES CXX)
#保留CUDA编译选项
if(WIN32)
	option(WIN64 "Make x64 build" ON)

	if(WIN64)
		find_package(IntelDPCPP REQUIRED)
		option(USE_CUDA "Build with CUDA support" ON)
		add_definitions(-DWIN64)
		set(wxWidgets_INCLUDE_DIRS "$ENV{WX_WIDGETS_PATH}/lib/vc_x64_lib/mswu;$ENV{WX_WIDGETS_PATH}/include" CACHE STRING "Paths to OpenCV include dirs")
		set(OpenCV_INCLUDE_DIRS "$ENV{OPENCV_BUILD_PATH_X64}/install/include" CACHE STRING "Paths to OpenCV include dirs")
		set(FFMPEG_INCLUDE_DIRS "$ENV{FFMPEG_PATH_X64}/include" CACHE STRING "Paths to FFMPEG include dirs")
		set(VideoSubFinderWXW_LINK_DIRS "$ENV{WX_WIDGETS_PATH}/lib/vc_x64_lib;$ENV{OPENCV_BUILD_PATH_X64}/lib/Release;$ENV{CUDA_TOOLKIT_PATH}/lib/x64;$ENV{FFMPEG_PATH_X64}/lib" CACHE STRING "VideoSubFinderWXW link dirs")
	else()
		option(USE_CUDA "Build with CUDA support" OFF)
		add_definitions(-DWINX86)
		set(wxWidgets_INCLUDE_DIRS "$ENV{WX_WIDGETS_PATH}/lib/vc_lib/mswu;$ENV{WX_WIDGETS_PATH}/include" CACHE STRING "Paths to OpenCV include dirs")
		set(OpenCV_INCLUDE_DIRS "$ENV{OPENCV_BUILD_PATH_X86}/install/include" CACHE STRING "Paths to OpenCV include dirs")
		set(FFMPEG_INCLUDE_DIRS "$ENV{FFMPEG_PATH_X86}/include" CACHE STRING "Paths to FFMPEG include dirs")
		set(VideoSubFinderWXW_LINK_DIRS "$ENV{WX_WIDGETS_PATH}/lib/vc_lib;$ENV{OPENCV_BUILD_PATH_X86}/lib/Release;$ENV{FFMPEG_PATH_X86}/lib" CACHE STRING "VideoSubFinderWXW link dirs")
	endif(WIN64)

	set(OpenCV_LIBS "opencv_world$ENV{OPENCV_LIBS_VER}.lib" CACHE STRING "Required OpenCV libs for build")

else()
	option(USE_CUDA "Build with CUDA support" ON)
	if(CMAKE_BUILD_TYPE STREQUAL "Debug")
		set(wxWidgets_USE_DEBUG ON)
	else()
		set(wxWidgets_USE_DEBUG OFF)
	endif()
	find_package(wxWidgets REQUIRED COMPONENTS core base aui)
	find_package(OpenCV REQUIRED)
	if(USE_CUDA)
		set(CUDA_LINK_DIRS "$ENV{CUDA_TOOLKIT_PATH}//lib64;$ENV{CUDA_TOOLKIT_PATH}//extras/CUPTI/lib64" CACHE STRING "CUDA link dirs")
	endif(USE_CUDA)
endif(WIN32)

if(USE_CUDA)
	set(CMAKE_CUDA_FLAGS "-arch=all")
	add_definitions(-DUSE_CUDA)
	set(CUDAKernels_INCLUDE_DIRS "../CUDAKernels")
	set(CUDAKernels_LIB "CUDAKernels;cudart;nppicc;nppig")
	add_subdirectory(Components/CUDAKernels)
else()
	set(CUDAKernels_INCLUDE_DIRS "")
	set(CUDAKernels_LIB "")
endif(USE_CUDA)

add_subdirectory(Components/IPAlgorithms)
add_subdirectory(Components/OCVVideo)
add_subdirectory(Components/FFMPEGVideo)
add_subdirectory(Interfaces/VideoSubFinderWXW)

install(TARGETS VideoSubFinderWXW DESTINATION VideoSubFinder)
install(DIRECTORY Data/bitmaps/ DESTINATION VideoSubFinder/bitmaps)
install(DIRECTORY Settings/Localization/ DESTINATION VideoSubFinder/settings FILES_MATCHING PATTERN "*.cfg")
install(FILES Settings/general.cfg DESTINATION VideoSubFinder/settings)

file(GLOB readme_files "Docs/readme*.txt")
install(FILES ${readme_files} DESTINATION VideoSubFinder/Docs)
